<?php
$this->breadcrumbs=array(
	'综合控制台'=>array($this->pre_module_url.'/index/index'),
	'广告管理'=>array($this->pre_module_url.'/adse/admin'),	
	'编辑广告'
);
?>
<?php 
			$form = $this->beginWidget('CActiveForm', 
			array(
			'id'=>'zdse-form',
			//'enableAjaxValidation'=>true,
			'enableClientValidation'=>true,	
			'action'=>$this->pre_module_url.'/adse/update',
			)); ?>
				<?php echo $form->hiddenfield($model,'zds_id'); ?>
                <ul class="form_list form_list2 mt10">
                	<li class="c_f"><span class="tit">选择页面：</span>
                        <div class="cont f_l">
							<?php 
                                echo CHtml::dropDownList('Adse[zna_id]',$menu1['zna_id'],Nav::model()->getTopData(),array('class'=>'mr10 s_ipt level_1 w_170','onchange'=>'afterSelect(1,this.value)','id'=>'menuselect1')); 
                                if($menu2){
                                    echo CHtml::dropDownList('Adse[zna_id2]',$menu2['zna_id'],Nav::model()->getChildData($menu1['zna_id']),array('class'=>'mr10 s_ipt level_1 w_170','onchange'=>'afterSelect(2,this.value)','id'=>'menuselect2')); 
                                    if($menu3){
                                        echo CHtml::dropDownList('Adse[zna_id3]',$menu3['zna_id'],Nav::model()->getChildData($menu2['zna_id']),array('class'=>'mr10 s_ipt level_1 w_170','onchange'=>'afterSelect(3,this.value)','id'=>'menuselect3')); 
                                    }
                                }
                            ?>
                        </div>
                    </li>
                	<li class="c_f"><span class="tit">选择广告位：</span>
                        <div class="cont f_l" id="adzonebox">
                       		<?php echo $form->dropDownList($model,'zdz_id',Adzone::model()->getAdzonesForSelect($adzone->zna_id),array('class'=>'s_ipt w_170','id'=>"adzoneselect")); ?>
                        </div>
                    </li>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_title'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_title',array('class'=>'t_ipt w_300','maxlength'=>30)); ?></div>
                        <span id="zdstitle"><?php echo $form->error($model,'zds_title',array('class'=>'onCorrect d_i c_red2')); ?></span>
                    </li>
                    <li class="c_f">
                    	<span class="tit"><?php echo $form->label($model,'zds_desc'); ?>：</span>
						<div class="cont f_l"><?php echo $form->textarea($model,'zds_desc',array('class'=>'t_area','style'=>'height:65px;width:500px;')); ?></div>
                    	<span id="zdsdesc"><?php echo $form->error($model,'zds_desc',array('class'=>'onCorrect d_i c_red2')); ?></span>
                    </li>
                    <?php
                    	if($adzone->zdz_type==1){
					?>
                            <li class="c_f"><span class="tit">广告图片：</span>                                
                                <div class="cont f_l">
                                    <div class="uploadimg">
                                        <img id="img1" src="<?php if(!empty($model->zds_file_url)){echo $model->zds_file_url;}else{echo "/images/pro_img.jpg";}?>" alt="" width="200" />
                                    </div>
                                    <p class="mt10">
                                        <?php echo CHtml::link('上传图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b>'.CHtml::fileField('image','',array('id'=>'uploadimg1','multiple'=>true)),'javascript:',array('class'=>'mem_bgx link_btn filelink mr20','onclick'=>"uploadimg('1')"))?>
                                        <?php echo $form->hiddenField($model,'zds_file_url',array('id'=>'proimage1'))?>  
                                    </p>  
                                    <script src="<?php echo Yii::app()->baseUrl;?>/js/upload_img.js"></script>
                                    <p class="c_999">最佳图片大小 <strong class="c_green3 ff_s"><?php echo $adzone->zdz_width.'*'.$adzone->zdz_height; ?></strong> </p>
                                </div>
                            </li>
                    <?php							
						}else{
					?>
                            <li class="c_f"><span class="tit">swf文件：</span>
                                <div class="cont f_l">
                                    <div class="adv_img f_l"><?php echo $form->textField($model,'zds_file_url',array('class'=>'t_ipt w_300','id'=>'swf1')); ?></div>
                                    <div class="adv_disc"><button class="mem_btn mem_btn13" onclick="file2.click();" id="file2button" type="button" name="" value="" >修改...</button></div>
                                    <div class="adv_disc f_l">
                                    	<input id="file2" class="d_n" type="file" onclick="uploadswf('file2')" value="" name="imgFile" />
                                        <p class="c_999">显示大小： <strong class="c_green3 ff_s"><?php echo $adzone->zdz_width.'*'.$adzone->zdz_height; ?>px</strong> </p>
                                    </div>
                                </div>
                            </li>
                    <?php					
						}					
					?>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_img_alt'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_img_alt',array('class'=>'t_ipt w_170','maxlength'=>100)); ?></div>
                    </li>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_url'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_url',array('class'=>'t_ipt w_170','maxlength'=>200)); ?></div>
                    </li>
                    <?php
                    	if($adzone->zdz_associate){
					?>
                        <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_category'); ?>：</span>
                            <div class="cont f_l">
                                <?php 
                                    foreach($category as $key=>$value){
                                        echo '<input type="checkbox" name="Adse[categorys][]" value="'.$key.'"'.(in_array($key,$model->zds_category)?' checked ':' ').'><b>'.$value[$catkey['title']].'</b></br>';
                                        if(isset($value['subcat'])){
                                            foreach($value['subcat'] as $subkey=>$subvalue){
                                            echo '<input type="checkbox" name="Adse[categorys][]" value="'.$subkey.'"'.(in_array($subkey,$model->zds_category)?' checked ':' ').'>'.$subvalue[$catkey['title']];
                                        }
                                        }
                                        echo '</br>';
                                        if(isset($value['subcat']) && count($value['subcat'])){
                                            echo '</br>';
                                        }
                                    }
                                ?>
                             </div>
                        </li>
                    <?php					
						}					
					?>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_name'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_name',array('class'=>'t_ipt w_170','maxlength'=>10)); ?></div>
                    </li>
                    <li class="c_f"><span class="tit"><?php echo $form->labelEx($model,'zds_mob'); ?>：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_mob',array('class'=>'t_ipt w_170','maxlength'=>11)); ?></div>
                    </li>
                    <li class="c_f"><span class="tit">广告价格：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_price',array('class'=>'t_ipt w_100','maxlength'=>5)); ?>元</div>
                    </li>
                    <li class="c_f"><span class="tit">开始时间：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_start_time',array('class'=>'t_ipt w_170','maxlength'=>50,'onclick'=>"WdatePicker()")); ?></div>
                    </li>
                    <li class="c_f"><span class="tit">结束时间：</span>
                        <div class="cont f_l"><?php echo $form->textField($model,'zds_end_time',array('class'=>'t_ipt w_170','maxlength'=>50,'onclick'=>"WdatePicker()")); ?></div>
                    </li>
                    <li class="c_f"><span class="tit">&nbsp;</span>
                        <div class="cont f_l"><input class="mem_btn mem_btn20 mr5" type="submit" name="" value="保存广告" /><input class="mem_btn mem_btn07" type="button" name="" value="取 消" /></div>
                    </li>
                </ul>	
            <?php $this->endWidget(); ?>
<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/My97DatePicker/WdatePicker.js"></script> 
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.ui.widget.js'></script> 
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.iframe-transport.js'></script> 
<script src='<?php echo Yii::app()->baseUrl;?>/js/jquery.fileupload.js'></script> 
<script>
	function afterSelect(level,menuid){
		$('#menuselect'+level).nextAll().remove();
		menuid = parseInt(menuid)==0 ? -1 : menuid;
		$.getJSON("/manage/nav/getchildmenu", { menuid: menuid, level: level }, function(data){
			if(data.amount){
				var nextLevel=parseInt(data.level)+1;
				var next = '<select class="level_'+(nextLevel)+' mr10 s_ipt w_170" onchange="afterSelect('+(nextLevel)+',this.value)" id="menuselect'+(nextLevel)+'" name="Adzone[zna_id'+(nextLevel)+']">';
				next += '<option value="">请选择</option>';
				$.each(data.items, function(i,item){
					next += '<option value="'+i+'">'+item+'</option>';
				});
				next += '</select>';
				$('#menuselect'+data.level).after(next);
			}
			$.getJSON("/manage/adzone/getadzonelist", { menuid: data.menuid, level: data.level }, function(list){
				var text = '<select class="mr10 s_ipt w_170" name="Adse[zdz_id]" id="adzoneselect">';
				text += '<option value="">请选择</option>';
				$.each(list.items, function(i,item){
					text += '<option value="'+i+'">'+item+'</option>';
				});
				text += '</select>';
				$('#adzonebox').html(text);
			});
		});
	}

//上传图片
function uploadimg (id) {
     $('#uploadimg'+id).fileupload({          
          dataType: 'json',       
          url: '/Attachment/GetAjax',        
          success: function (json) {
                 if(json.upfile.errors=='1'){
                    alert(json.upfile.msg);
                 }else if(json.upfile.errors=='2'){
                    alert(json.upfile.msg);
                 }else{                   
                     //修改按钮图标
                   $('#img'+id).attr('src',json.upfile.file);
             //修改按钮文本
                   $('#uploadimg'+id).parent().html('修改图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b><input type="file" id="uploadimg'+id+'" multiple name="image"/>');
                   //填加删除按钮
                   if(!$('#img'+id).parent().parent().find('a')[1]){
                     $('#img'+id).parent().parent().find('a').eq(0).after('<a class="mem_bgx link_btn" href="javascript:" onclick="removeimg(\''+id+'\')">删除图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b></a>');
                   }
             //修改隐藏域值
                     $('#proimage'+id).attr('value',json.upfile.file);
                 }  
          }
      });
};
//删除图片
function removeimg(id){
  $('#img'+id).parent().parent().find('a').eq(0).html('上传图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b><input type="file" id="uploadimg'+id+'" multiple name="image"/>');
  $('#img'+id).parent().parent().find('a').eq(1).remove();
  $('#img'+id).attr('src','/images/cert_img.jpg');
  $('#proimage'+id).attr('value','');
}
   function uploadswf (id) {
		   $('#'+id).fileupload({         	
				dataType: 'json',
				url: '/Attachment/GetAjax',        
				success: function (json) {
					   if(json.upfile.errors=='1'){
							alert(json.upfile.msg);
					   }else if(json.upfile.errors=='2'){
							alert(json.upfile.msg);
					   }else{
							 //修改按钮文本
							 $('#'+id+'button').text('修改...');
							 //修改隐藏域值
							 $('#swf1').attr('value',json.upfile.file);
					   } 	
				}
			});
	};		
 </script>